from django import forms
from .models import Asset

class AssetForm(forms.ModelForm):
    """设备表单"""
    class Meta:
        model = Asset
        fields = ['name', 'model', 'asset_type', 'serial_number', 
                 'purchase_date', 'purchase_price', 'department', 'status', 'notes']
        widgets = {
            'name': forms.TextInput(attrs={'class': 'form-control', 'placeholder': '设备名称'}),
            'model': forms.TextInput(attrs={'class': 'form-control', 'placeholder': '设备型号'}),
            'asset_type': forms.Select(attrs={'class': 'form-control'}),
            'serial_number': forms.TextInput(attrs={'class': 'form-control', 'placeholder': '序列号'}),
            'purchase_date': forms.DateInput(attrs={'class': 'form-control', 'type': 'date'}),
            'purchase_price': forms.NumberInput(attrs={'class': 'form-control', 'placeholder': '购买价格'}),
            'department': forms.TextInput(attrs={'class': 'form-control', 'placeholder': '所属部门'}),
            'status': forms.Select(attrs={'class': 'form-control'}),
            'notes': forms.Textarea(attrs={'class': 'form-control', 'rows': 3, 'placeholder': '备注信息'}),
        }
        labels = {
            'name': '设备名称',
            'model': '设备型号',
            'asset_type': '设备类型',
            'serial_number': '序列号',
            'purchase_date': '购买日期',
            'purchase_price': '购买价格',
            'department': '所属部门',
            'status': '设备状态',
            'notes': '备注',
        }

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        # 设置必填字段
        self.fields['name'].required = True
        self.fields['asset_type'].required = True
        self.fields['status'].required = True
